import { createStore } from 'vuex'
import persist from 'vuex-persistedstate'
export default createStore({
  state: {
    history:[], // 历史记录
  },
  mutations: {
    addHistory(state,val){ // 添加历史记录
      let index = state.history.findIndex(item => item.geohash == val.geohash)
      if (index > -1){
        state.history.splice(index,1);
      }
      state.history.unshift(val);
      state.history.splice(5,1); // 不允许长度大于5
    },
    clear(state){
      state.history = [] // 清空历史记录
    }
  },
  actions: {
  },
  modules: {
  },
  plugins: [
    new persist({
      storage: window.localStorage,
    }),
  ]
})
